#include "Execution.h"

void Execution::mainthread(){
    //Messy Codes Here:
    
    vector<string> container;
    myinterface.Input();
    
    try {
        Reader.readfile(container, myinterface.getInputfilename());
    }
    
    catch(FileException error){
        cout<<"Error:  "<<error.getexception()<<endl;
    }
    
    vector<string> temp;
    
    int index=0;
    cout<<container.size()<<endl;

            
       
    try {
        while(index<container.size()){
        mymanipulator.splitstream(container.at(index), "=");
        temp = mymanipulator.getstream();
        cout<<temp.size()<<" "<<temp.at(0)<<endl;
  //      mymanipulator.findandreplace(temp.at(0), NULL, "");
        mymanipulator.findandreplace(temp.at(1), " ", "");
        
        Writer.writefile(temp, myinterface.getOutputfilename());
        
        mymanipulator.clear_result_stream();
        index++;
        }
    }
    
    catch(FileException error){
        cout<<"Error:  "<<error.getexception()<<endl;
    }
    /*
    myinterface.Input();
    try{
       Tester.readfile(testercontainer, myinterface.getInputfilename()); //read file
    }
    
    catch(FileException error){  //The Identifier "error" or any identifier on the catch parameter field
                                 // can be omitted if it's not going to be used  in the block
        cout<<error.what()<<endl<<"The File: -->> "<<error.getfilename()<<" <<-- Does not Exist!"<<endl<<error.getexception()<<endl;
        throw;
    }
    counter=0;      
    vector<string> newcontainer;
    while(testercontainer.size()>counter){
         mymanipulator.splitstream(testercontainer.at(counter), "=" );
         newcontainer = mymanipulator.getstream();
  
         counter++;
    }
    
    try {
        TesterW.writefile(newcontainer, myinterface.getOutputfilename());  
    }
    
    catch (FileException error){
        cout<<error.what()<<endl<<error.getexception()<<endl;
        throw;
    }
    testercontainer.clear();
    newcontainer.clear();
    mymanipulator.clear_result_stream();
    counter=0;

    myinterface.Input("Replace");
    
    try{
       Tester.readfile(testercontainer, myinterface.getInputfilename());
    }
    
    catch (FileException error){
        cout<<error.what()<<endl<<error.getexception()<<endl;
        throw;
    }
    
    while(testercontainer.size()>counter) {
        mymanipulator.findandreplace(testercontainer.at(counter),"c", "SPACE");
        newcontainer = mymanipulator.getstream(); //The equal operator for vector is the same as pushback member function
        counter++;
    }
    
    try{
        TesterW.writefile(newcontainer, myinterface.getOutputfilename());   
    }
    
    catch (FileException error){
        cout<<error.what()<<endl<<error.getexception()<<endl;
        throw;
    }
    */
}